var gulp = require("gulp");
var babel = require("gulp-babel");
var sourcemaps  = require('gulp-sourcemaps');
var uglify      = require('gulp-uglify');
var concat = require('gulp-concat');
var minifycss=require('gulp-minify-css');
var connect = require('gulp-connect');//livereload

gulp.task('es6',function(){
    gulp.src("src/js/*.js")
        .pipe(concat("all-min.js"))
        .pipe(sourcemaps.init())
        .pipe(babel({presets:['es2015']}))
        .pipe(uglify())
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest('dist/js'))
        .pipe(connect.reload());
        console.log("js处理完毕");
});

gulp.task('css',function(){
    gulp.src("src/css/*.css")
        .pipe(concat("all-min.css"))
        .pipe(minifycss())
        .pipe(gulp.dest('dist/css'))
        .pipe(connect.reload());
        console.log("css处理完毕");
});

gulp.task('html',function(){
    gulp.src("src/*.html")
        .pipe(gulp.dest('dist'))
        .pipe(connect.reload());
    console.log("html处理完毕");
});

gulp.task('connect', function () {
         connect.server({
             root:'dist',
             livereload: true
         });
});

gulp.task('watch',function(){
   gulp.watch('src/js/*.js',['es6']);
   gulp.watch('src/css/*.css',['css']);
   gulp.watch('src/*.html',['html']);
});


gulp.task('default',['html','es6','css','watch','connect'],function(){
    console.log("开发环境处理完毕");
    console.log("文件开始监听");
});

